package com.kylin.log.kafka;

import com.alibaba.fastjson.JSON;
import com.kylin.log.service.LogService;
import com.kylin.common.log.entity.AopLogEntity;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class KafkaConsumerWebLog {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    LogService logService;

    @KafkaListener(topics="kylinLog")
    public void saveLog(ConsumerRecord<?,?> consumerRecord){
        logger.info("请求controller的日志为：{}",consumerRecord.value().toString());
        logService.saveLog(JSON.parseObject(consumerRecord.value().toString(), AopLogEntity.class));
    }

}
